#include"game.h"

void  menus()
{
	printf("***********************************\n");
	printf("***********1.game     *************\n");
	printf("***********0.over     *************\n");
	printf("***********************************\n");
}

void game()
{
	srand((unsigned int)time(NULL));
	char start[LINES][ROWS];
	char show[LINES][ROWS];
	initialization(start, LINES, ROWS);
	
	show_show(start, LINES, ROWS);
	initialize(show, LINES, ROWS);
	int a=0;
	while (a<LINE*ROW-NUMBER)
	{
		printf("input two\n");
		int i, j;
		scanf_s("%d%d", &i, &j);
		if (i > 0 && i < LINES - 1 && j>0 && j < ROWS - 1)
		{
			if (start[i][j] == '1')
			{
				printf("game over\n");
				break;
			}
			else if (start[i][j] == '0')
			{
				show[i][j] = (start[i - 1][j - 1] + start[i - 1][j] +
					start[i - 1][j + 1] + start[i][j - 1] +
					start[i][j + 1] + start[i + 1][j - 1] +
					start[i + 1][j] + start[i + 1][j + 1]) - 7 * '0';
			}
		}
		show_show(show, LINES, ROWS);
		a++;
	}
	if (a == LINE * ROW - NUMBER)
		printf("win\n");
}




void initialization(char table[LINES][ROWS], int line, int row)
{
	int i, j;
	for (i = 0; i < line; i++)
	{
		for (j = 0; j < row; j++)
		{
			table[i][j] = '0';
		}
	}
	int a=0;
	while (a <NUMBER)
	{
		i = rand()%LINE+1;
		j = rand()%ROW+1;
		if (table[i][j] != '1')
		{
			table[i][j] = '1';
			a = a + 1;
		}
		
	}
}
void show_table(char table[LINES][ROWS], int line, int row)
{
	int i, j;
		
	for (i = 0; i < line; i++)
	{
		
		for (j = 0; j < row; j++)
		{
			printf("%c ", table[i][j]);
		}
		printf("\n");
	}
}
void initialize(char show[LINES][ROWS], int line, int row)
{
	int i, j;
	for (i = 0; i < line; i++)
	{
		for (j = 0; j < line; j++)
		{
			show[i][j] = '*';
		}
	}
}
void show_show(char show[LINES][ROWS], int line, int row)
{
	int i, j;
	for (i = 0; i < line-1; i++)
	{
		printf("%d ", i);
	}
	printf("\n");
	for (i = 1; i < line - 1; i++)
	{
		printf("%d ", i);
		for (j = 1; j < row-1; j++)
		{
			printf("%c ", show[i][j]);
		}
		printf("\n");
	}
}